package com.example.lenovo.liweixin1601v20180702.v.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.example.lenovo.liweixin1601v20180702.R;
import com.example.lenovo.liweixin1601v20180702.m.bean.NewBean;
import com.example.lenovo.liweixin1601v20180702.m.model.Model;
import com.example.lenovo.liweixin1601v20180702.p.Presenter;
import com.example.lenovo.liweixin1601v20180702.v.adapter.NewsAdapter;
import com.example.lenovo.liweixin1601v20180702.v.view.IMoadView;

import java.util.List;

public class MainActivity extends AppCompatActivity implements IMoadView {

    private RecyclerView recy;
    private Presenter presenter;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }

    private void initView() {
        btn = findViewById(R.id.news_btn);
        recy = findViewById(R.id.recy);
        recy.setLayoutManager(new LinearLayoutManager(this));
    }

    private void initData() {
        Presenter presenter = new Presenter();
        presenter.showToView(new Model(),this);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, gwcActivity.class);
                startActivity(intent);

            }
        });
    }

    @Override
    public void showNew(List<NewBean.DataBean.Discounts2Bean> list) {
       final NewsAdapter newsAdapter = new NewsAdapter(MainActivity.this,list);
       recy.setAdapter(newsAdapter);
    }

    //防止内存泄漏
    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.onDestory();
    }
}
